﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Shared/_LayuiList.cshtml";
}

<input style="display: none" name="tbid" id="tbid" value="@ViewBag.tbid">
<input style="display: none" name="date" id="date" value="@ViewBag.date">
<blockquote class="layui-elem-quote layui-text">
    设置Configs/appSet.config文件中的CopyCodeStr参数，重新生成时系统自动备份将被替换的文件至wwwroot/TempCode文件夹中；通过录入表管理/代码管理可手动备份
</blockquote>
<!--数据表格-->
<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
<script src="~/lib/layui/layui.js" charset="utf-8"></script>

<script>
    layui.use(["table", "form", "exLayer", "exUtils"], function () {
        let table = layui.table;
        let form = layui.form;
        let exLayer = layui.exLayer;
        let exUtils = layui.exUtils;

        let $ = layui.$;

        form.render(); //

        $("#blockquote_close").click(function () {
            $(".layui-elem-quote").attr("style", "display:none");
            $("#blockquote_close").attr("style", "display:none");
        });

        let ThisTable = table.render({
            elem: "#tableId",
            url: "/SysBasic/TempletCode/GetTempDirectory?tbid=" + $("#tbid").val(),
            page: false,
            defaultToolbar: [{ title: '显示所有数据', layEvent: 'refresh', icon: 'layui-bg-blue layui-icon-refresh' }, 'exports', 'filter'],
            toolbar: "#toolbarTpl",
            cols: [[
                { type: "checkbox", fixed: 'left' },
                { type: "numbers", title: "NO.", fixed: 'left' },
                { field: "FilePath", title: "路径", sort: true, width: layui.device().mobile ? 200 : null },
                { title: "操作", width: 80, align: "center", fixed: layui.device().mobile ? null : 'right', templet: "#operationTpl" }
            ]],
            done: function (res, curr, count) {
                console.log(res, curr, count);
                if (layui.device().mobile) {
                    $("#batchDel").html('<i class="fa fa-trash-o"></i>删除');
                }
            }
        });

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "creat":
                    creat();
                    break;
                case "batchDel":
                    batchDel();
                    break;
                case "refresh":
                    refresh();
                    break;
            }
        });

        table.on("tool(tableFilter)", function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case "detail":
                    detail(data.FileName);
                    break;
            }
        });

        function refresh() {
            ThisTable.reload({
                url: "/SysBasic/TempletCode/GetTempDirectory?tbid=" + $("#tbid").val()
            });
        }

        function detail(date) {
            exLayer.open("查看", "/SysBasic/TempletCode/TempCode?tbid=" + $("#tbid").val() + "&date=" + date, '100%', '100%', '0px', '0px', null, null);
        }

        function batchDel() {
            var idsStr = "";
            var checkStatus = table.checkStatus("tableId");
            var rows = checkStatus.data.length;
            if (rows > 0) {
                for (var i = 0; i < checkStatus.data.length; i++) {
                    idsStr += checkStatus.data[i].FilePath + ",";
                }
            } else {
                layer.msg("未选择有效数据");
                return false;
            }
            exLayer.confirm("确定要删除吗？", function (index) {
                layer.close(index);
                if (idsStr) {
                    exUtils.ajax("/SysBasic/TempletCode/BatchDelDirectory", "post", { idsStr: idsStr }, true).done(function (response) {
                        exUtils.tableSuccessMsg(response.message);
                        refresh();
                    }).fail(function (error) {
                        console.log(error);
                    });
                }
            });
        }
    });
</script>
<script type="text/html" id="toolbarTpl">
    <button type="button" class="layui-btn layui-btn-danger layui-btn-sm" lay-event="batchDel" id="batchDel"><i class="fa fa-trash-o"></i>批量删除</button>
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
    <a class="layui-btn layui-btn-normal layui-btn-xs" href="javascript:;" lay-event="detail" id="detail">查看</a>
</script>